home *** CD-ROM | disk | FTP | other *** search
/ Chip 1998 September / CHIP Eylül 1998.iso / Slackwar / docs / mini / Software-RAID < prev    next >
Text File  |  1998-01-05  |  59KB  |  1,451 lines

  1.   Software-RAID mini-HOWTO
  2.   Linas Vepstas, linas@linas.org
  3.   v0.38 28 December 1997
  4.  
  5.   RAID stands for ''Redundant Array of Inexpensive Disks'', and is meant
  6.   to be a way of creating a fast and reliable disk-drive subsystem out
  7.   of individual disks.  This document is a tutorial/HOWTO/FAQ for users
  8.   of the Linux MD kernel extension, the associated tools, and their use.
  9.   The MD extension implements RAID-0 (stripping), RAID-1 (mirroring),
  10.   RAID-4 and RAID-5 in software. That is, with MD, no special hardware
  11.   or disk controllers are required to get many of the benefits of RAID.
  12.   This document is NOT an introduction to RAID; you must find this else¡
  13.   where.
  14.  
  15.      Preamble
  16.         This document is GPL'ed by Linas Vepstas (linas@linas.org).
  17.         Permission to use, copy, distribute this document for any
  18.         purpose is hereby granted, provided that the author's / editor's
  19.         name and this notice appear in all copies and/or supporting
  20.         documents; and that an unmodified version of this document is
  21.         made freely available.  This document is distributed in the hope
  22.         that it will be useful, but WITHOUT ANY WARRANTY, either
  23.         expressed or implied.  While every effort has been taken to
  24.         ensure the accuracy of the information documented herein, the
  25.         author / editor / maintainer assumes NO RESPONSIBILITY for any
  26.         errors, or for any damages, direct or consequential, as a result
  27.         of the use of the information documented herein.
  28.  
  29.         RAID, although designed to improve system reliability by adding
  30.         redundancy, can also lead to a false sense of security and
  31.         confidence when used improperly.  This false confidence can lead
  32.         to even greater disasters.  In particular, note that RAID is
  33.         designed to protect against *disk* failures, and not against
  34.         *power* failures. A power failure can damage data on the disks
  35.         in such a way that it is not recoverable!  RAID is *not* a
  36.         substitute for proper backup of your system.  Know what you are
  37.         doing, test, be knowledgeable and aware!
  38.  
  39.   1.  Introduction
  40.  
  41.   1. Q: What is RAID?
  42.  
  43.        A: RAID stands for "Redundant Array of Inexpensive Disks",
  44.        and is meant to be a way of creating a fast and reliable
  45.        disk-drive subsystem out of individual disks.
  46.  
  47.   2. Q: What is this document?
  48.  
  49.        A: This document is a tutorial/HOWTO/FAQ for users of the
  50.        Linux MD kernel extension, the associated tools, and their
  51.        use.  The MD extension implements RAID-0 (stripping), RAID-1
  52.        (mirroring), RAID-4 and RAID-5 in software.   That is, with
  53.        MD, no special hardware or disk controllers are required to
  54.        get many of the benefits of RAID.
  55.  
  56.        This document is NOT an introduction to RAID; you must find
  57.        this elsewhere.
  58.  
  59.   3. Q: What levels of RAID does the Linux kernel implement?
  60.  
  61.        A: Striping (RAID-0) and linear concatenation are a part of
  62.        the stock 2.x series of kernels.  This code is of production
  63.        quality; it is well understood and well maintained.  It is
  64.        being used in some very large USENET news servers.
  65.  
  66.        RAID-1, RAID-4 & RAID-5 are not present in the stock kernel;
  67.        a separate patch needs to be applied to get this functional¡
  68.        ity.  The current snapshots should be considered beta qual¡
  69.        ity; that is, there are no known bugs but there are some
  70.        rough edges and untested system setups.
  71.  
  72.        RAID-1 hot reconstruction has been recently introduced
  73.        (August 1997) and should be considered alpha quality.
  74.        RAID-5 hot reconstruction will be alpha quality any day now.
  75.  
  76.   4. Q: Where do I get it?
  77.  
  78.        A: Software RAID-0 and linear mode are a stock part of all
  79.        current Linux kernels.  Patches for Software RAID-1,4,5 are
  80.        available from
  81.        <http://luthien.nuclecu.unam.mx/~miguel/raid>.  See also the
  82.        quasi-mirror
  83.        <ftp://linux.kernel.org/pub/linux/daemons/raid/> for
  84.        patches, tools and other goodies.
  85.  
  86.   5. Q: Are there other Linux RAID references?
  87.  
  88.        A:
  89.  
  90.        ╖  Generic RAID overview:
  91.           <http://www.dpt.com/uraiddoc.html>.
  92.  
  93.        ╖  General Linux RAID options:
  94.           <http://linas.org/linux/raid.html>.
  95.  
  96.        ╖  Linux-RAID mailing list archive:
  97.           <http://www.linuxhq.com/lnxlists>.
  98.  
  99.        ╖  Linux Software RAID Home Page:
  100.           <http://luthien.nuclecu.unam.mx/~miguel/raid>.
  101.  
  102.        ╖  Linux Software RAID tools:
  103.           <ftp://linux.kernel.org/pub/linux/daemons/raid/>.
  104.  
  105.        ╖  How to setting up linear/stripped Software RAID:
  106.           <http://www.ssc.com/lg/issue17/raid.html>.
  107.  
  108.        ╖  Bootable RAID mini-HOWTO:
  109.           <ftp://ftp.bizsystems.com/pub/raid/bootable-raid>.
  110.  
  111.        ╖  Linux RAID-Geschichten:
  112.           <http://www.infodrom.north.de/~joey/Linux/raid/>.
  113.  
  114.   6. Q: Who do I blame for this document?
  115.  
  116.        A: Linas Vepstas slapped this thing together.  However, most
  117.        of the information, and some of the words were supplied by
  118.   ╖  Bradley Ward Allen <ulmo@Q.Net>
  119.  
  120.   ╖  Luca Berra <bluca@comedia.it>
  121.  
  122.   ╖  Brian Candler <B.Candler@pobox.com>
  123.  
  124.   ╖  Bohumil Chalupa <bochal@apollo.karlov.mff.cuni.cz>
  125.  
  126.   ╖  Anton Hristozov <anton@intransco.com>
  127.  
  128.   ╖  Miguel de Icaza <miguel@luthien.nuclecu.unam.mx>
  129.  
  130.   ╖  Ingo Molnar <mingo@pc7537.hil.siemens.at>
  131.  
  132.   ╖  Alvin Oga <alvin@planet.fef.com>
  133.  
  134.   ╖  Gadi Oxman <gadio@netvision.net.il>
  135.  
  136.   ╖  Michael Robinton <michael@bzs.org>
  137.  
  138.   ╖  Martin Schulze <joey@finlandia.infodrom.north.de>
  139.  
  140.   ╖  Geoff Thompson <geofft@cs.waikato.ac.nz>
  141.  
  142.   ╖  Edward Welbon <welbon@bga.com>
  143.  
  144.   ╖  Rod Wilkens <rwilkens@border.net>
  145.  
  146.   ╖  Johan Wiltink <j.m.wiltink@pi.net>
  147.  
  148.   ╖  Leonard N. Zubkoff <lnz@dandelion.com>
  149.  
  150.   ╖  Marc ZYNGIER <zyngier@ufr-info-p7.ibp.fr>
  151.  
  152.      Copyrights
  153.  
  154.   ╖  Copyright (C) 1994-96 Marc ZYNGIER
  155.  
  156.   ╖  Copyright (C) 1997 Gadi Oxman, Ingo Molnar, Miguel de
  157.      Icaza
  158.  
  159.   ╖  Copyright (C) 1997 Linas Vepstas
  160.  
  161.   ╖  By copyright law, additional copyrights are implicitly
  162.      held by the contributors listed above.
  163.  
  164.      Thanks all for being there!
  165.  
  166.   2.  Setup & Installation Considerations
  167.  
  168.   1. Q: I must soon install Linux on new system, one requirement is to
  169.      have RAID1.  Now I'm wondering what is the easiest way to do it.
  170.  
  171.        A: I keep rediscovering that file-system planning is one of
  172.        the more difficult Unix configuration tasks.  To answer your
  173.        question, I can describe what we did.
  174.  
  175.        We planned the following setup:
  176.  
  177.        ╖  two EIDE disks, 2.1.gig each.
  178.  
  179.   disk partition mount pt.  size    device
  180.     1      1       /        300M   /dev/hda1
  181.     1      2       swap      64M   /dev/hda2
  182.     1      3       /home    800M   /dev/hda3
  183.     1      4       /var     900M   /dev/hda4
  184.  
  185.     2      1       /root    300M   /dev/hdc1
  186.     2      2       swap      64M   /dev/hdc2
  187.     2      3       /home    800M   /dev/hdc3
  188.     2      4       /var     900M   /dev/hdc4
  189.  
  190.   ╖  each disk is on a separate controller (& ribbon cable).
  191.      The theory is that a controller failure and/or ribbon
  192.      failure won't disable both disks.  Possibly get
  193.      performance boost from parallel operations?
  194.  
  195.   ╖  Install linux on / in /dev/hda1 this will allow booting
  196.      and subsequent installation of raid patches, etc.
  197.  
  198.   ╖  /dev/hdc1 will contain a ``cold'' copy of /dev/hda1. This
  199.      is NOT a raid copy, just a copy-copy. It's there just in
  200.      case disk1 fails completely; we can use a rescue disk,
  201.      mark /dev/hdc1 as bootable, and use that to keep going,
  202.      without having to reinstall the system.
  203.  
  204.      The theory here is that in case of severe failure, I can
  205.      still boot the system without worrying about raid
  206.      superblock-corruption or other raid failure modes &
  207.      gotchas that I don't understand.
  208.  
  209.   ╖  /dev/hda3 and /dev/hdc3 will be mirrors /dev/md0.
  210.  
  211.   ╖  /dev/hda4 and /dev/hdc4 will be mirrors /dev/md1.
  212.  
  213.   ╖  we picked /var and /home to be mirrored, and in separate
  214.      partitions, under the following (convoluted ???) logic:
  215.  
  216.   ╖  / will contain non-changing data --- for all practical
  217.      purposes, it will be read-only without actually being
  218.      read-only.
  219.  
  220.   ╖  /home will contain slowly changing data --- an almost-
  221.      read-only system.
  222.  
  223.   ╖  /var will contain rapidly changing data, including mail
  224.      spools, database contents and web server logs.
  225.  
  226.      The theory is that if for some bizarre reason, the
  227.      operating system goes wild, corruption is limited to one
  228.      partition.  Thus, if for some unlikely, hypothetical
  229.      reason, the database starts scribbling everywhere, it
  230.      might clobber mail and log files, but not /home.
  231.  
  232.      I am not entirely satisfied with my logic & reasoning,
  233.      but it was the best I could do on short notice.  I would
  234.      like to have some scheme that verifies that files in /usr
  235.      and /home are not changed, e.g. some MD5 signature scheme
  236.      that is run regularly.  The idea is to detect hacker
  237.      intrusion as well as corruption.  Similarly, the database
  238.      contents are quite valuable, and I don't have a fault-
  239.      tolerant plan for that that will let me sleep well at
  240.      night.
  241.      So, to complete the answer to your question:
  242.  
  243.   ╖  install redhat on disk 1, partition 1.  do NOT mount any
  244.      of the other partitions.
  245.  
  246.   ╖  install raid per instructions.
  247.  
  248.   ╖  configure md0 and md1.
  249.  
  250.   ╖  convince yourself that you know what to do in case of a
  251.      disk failure!  Discover sysadmin mistakes now, and not
  252.      during an actual crisis.  Experiment!  (we turned off
  253.      power during disk activity --- this proved to be ugly but
  254.      informative).
  255.  
  256.   ╖  do some ugly mount/copy/unmount/rename/reboot scheme to
  257.      move /var over to the /dev/md1.  Done carefully, this is
  258.      not dangerous.
  259.  
  260.   ╖  enjoy!
  261.  
  262.   2. Q: Can I strip/mirror the root partition (/)?  Why can't I boot
  263.      Linux directly from the md disks?
  264.  
  265.        A: Both Lilo and Loadlin need an non-stripped/mirrored par¡
  266.        tition to read the kernel image from. If you want to
  267.        strip/mirror the root partition (/), then create an
  268.        unstriped/mirrored partition.  Typically, this is /boot.
  269.        Then you either use the initial ramdisk support, or some old
  270.        patches that were posted a while back, to allow your root
  271.        device to be striped.
  272.  
  273.        There are several approaches that can be used.  One approach
  274.        is documented in detail in the Bootable RAID mini-HOWTO:
  275.        <ftp://ftp.bizsystems.com/pub/raid/bootable-raid>.
  276.  
  277.        Alternately, use mkinitrd to build the ramdisk image, see
  278.        below.
  279.  
  280.        Edward Welbon <welbon@bga.com> writes:
  281.  
  282.        ╖  To mount an md filesystem as root, the main thing is to
  283.           build an initial file system image that has the needed
  284.           modules and md tools to start md.  I have a simple script
  285.           that does this.
  286.  
  287.        ╖  For boot media, I have a small cheap SCSI disk (170MB I
  288.           got it used for $20).  This disk runs on a AHA1452, but
  289.           it could just as well be an inexpensive IDE disk on the
  290.           native IDE.  The disk need not be very fast since it is
  291.           mainly for boot.
  292.  
  293.        ╖  This disk has a small file system which contains the
  294.           kernel and the file system image for initrd.  The initial
  295.           file system image has just enough stuff to allow me to
  296.           load the raid SCSI device driver module and start the
  297.           raid partition that will become root.  I then do an
  298.  
  299.   echo 0x900 > /proc/sys/kernel/real-root-dev
  300.  
  301.   (0x900 is for /dev/md0) and exit linuxrc.  The boot proceeds
  302.   normally from there.
  303.  
  304.   ╖  I have built most support as a module except for the
  305.      AHA1452 driver that brings in the initrd filesystem.  So
  306.      I have a fairly small kernel. The method is perfectly
  307.      reliable, I have been doing this since before 2.1.26 and
  308.      have never had a problem that I could not easily recover
  309.      from.  The file systems even survived several 2.1.4[45]
  310.      hard crashes with no real problems.
  311.  
  312.   ╖  At one time I had partitioned the raid disks so that the
  313.      initial cylinders of the first raid disk held the kernel
  314.      and the initial cylinders of the second raid disk hold
  315.      the initial file system image, instead I made the initial
  316.      cylinders of the raid disks swap since they are the
  317.      fastest cylinders (why waste them on boot?).
  318.  
  319.   ╖  The nice thing about having an inexpensive device
  320.      dedicated to boot is that it is easy to boot from and can
  321.      also serve as a rescue disk if necessary. If you are
  322.      interested, you can take a look at the script that builds
  323.      my initial ram disk image and then runs lilo.
  324.  
  325.        <http://www.realtime.net/~welbon/initrd.md.tar.gz>
  326.  
  327.   It is current enough to show the picture.  It isn't espe¡
  328.   cially pretty and it could certainly build a much smaller
  329.   filesystem image for the initial ram disk.  It would be easy
  330.   to a make it more efficient.  But it uses lilo as is.  If
  331.   you make any improvements, please forward a copy to me. 8-)
  332.  
  333.   3. Q: I have heard that I can run mirroring over striping. Is this
  334.      true?  Can I run mirroring over the loopback device?
  335.  
  336.        A: Yes, but not the reverse.  That is, you can put a stripe
  337.        over several disks, and then build a mirror on top of this.
  338.        However, striping cannot be put on top of mirroring.
  339.  
  340.        A brief technical explanation is that the linear and stripe
  341.        personalities use the ll_rw_blk routine for access.  The
  342.        ll_rw_blk routine maps disk devices and  sectors, not
  343.        blocks.  Block devices can be layered one on top of the
  344.        other; but devices that do raw, low-level disk accesses,
  345.        such as ll_rw_blk, cannot.
  346.  
  347.        Currently (November 1997) RAID cannot be run over the loop¡
  348.        back devices, although this should be fixed shortly.
  349.  
  350.   4. Q: I have two small disks and three larger disks.  Can I
  351.      concatenate the two smaller disks with RAID-0, and then create a
  352.      RAID-5 out of that and the larger disks?
  353.        A: Currently (November 1997), for a RAID-5 array, no.  Cur¡
  354.        rently, one can do this only for a RAID-1 on top of the con¡
  355.        catenated drives.
  356.  
  357.   5. Q: What is the difference between RAID-1 and RAID-5 for a two-disk
  358.      configuration (i.e. the difference between a RAID-1 array  built
  359.      out of two disks, and a RAID-5 array built out of two disks)?
  360.  
  361.        A: There is no difference in storage capacity.  Nor can
  362.        disks be added to either array to increase capacity (see the
  363.        question below for details).
  364.  
  365.        RAID-1 offers a performance advantage for reads: the RAID-1
  366.        driver uses distributed-read technology to simultaneously
  367.        read two sectors, one from each drive, thus doubling read
  368.        performance.
  369.  
  370.        The RAID-5 driver, although it contains many optimizations,
  371.        does not currently (September 1997) realize that the parity
  372.        disk is actually a mirrored copy of the data disk.  Thus, it
  373.        serializes data reads.
  374.  
  375.   6. Q: How can I guard against a two-disk failure?
  376.  
  377.        A: Some of the RAID algorithms do guard against multiple
  378.        disk failures, but these are not currently implemented for
  379.        Linux.  However, the Linux Software RAID can guard against
  380.        multiple disk failures by layering an array on top of an
  381.        array.  For example, nine disks can be used to create three
  382.        raid-5 arrays.  Then these three arrays can in turn be
  383.        hooked together into a single RAID-5 array on top.  In fact,
  384.        this kind of a configuration will guard against a three-disk
  385.        failure.  Note that a large amount of disk space is
  386.        ''wasted'' on the redundancy information.
  387.  
  388.            For an NxN raid-5 array,
  389.            N=3, 5 out of 9 disks are used for parity (=55%percent;)
  390.            N=4, 7 out of 16 disks
  391.            N=5, 9 out of 25 disks
  392.            ...
  393.            N=9, 17 out of 81 disks (=~20%percent;)
  394.  
  395.   In general, an MxN arrary will use M+N-1 disks for parity.
  396.   The least amount of space is "wasted" when M=N.
  397.  
  398.   Another alternative is to create a RAID-1 array with three
  399.   disks.  Note that since all three disks contain identical
  400.   data, that 2/3's of the space is ''wasted''.
  401.  
  402.   7. Q: I'd like to understand  how it'd be possible to have something
  403.      like fsck: if the partition hasn't been cleanly unmounted, fsck
  404.      runs and fixes the filesystem by itself more than 90%percent; of
  405.      the time. Since the machine is capable of fixing it by itself with
  406.      ckraid --fix, why not make it automatic?
  407.  
  408.        A: Brian Candler <B.Candler@pobox.com> responds:
  409.  
  410.        Then you just put ckraid into your system initialization
  411.        scripts, like fsck is.  After the root partition is mounted,
  412.        add the following to /etc/rc.d/rc.sysinit:
  413.  
  414.            mdadd /dev/md0 /dev/hda1 /dev/hdc1 || {
  415.                ckraid --fix /etc/raid.usr.conf
  416.                mdadd /dev/md0 /dev/hda1 /dev/hdc1
  417.            }
  418.            mdadd /dev/md1 /dev/hda2 /dev/hdc2 || {
  419.                ckraid --fix /etc/raid.var.conf
  420.                mdadd /dev/md0 /dev/hda2 /dev/hdc2
  421.            }
  422.  
  423.   (Modify the above to suit your system.)
  424.  
  425.   Gadi Oxman explains the operation: In an unclean shutdown,
  426.   Linux might be in one of the following states:
  427.  
  428.   ╖  The in-memory disk cache was in sync with the RAID set
  429.      when the unclean shutdown occurred; no data was lost.
  430.  
  431.   ╖  The in-memory disk cache was newer than the RAID set
  432.      contents when the crash occurred; this results in a
  433.      corrupted filesystem and potentially in data loss.
  434.  
  435.      This state can be further divided to the following two
  436.      states:
  437.  
  438.   ╖  Linux was writing data when the unclean shutdown
  439.      occurred.
  440.  
  441.   ╖  Linux was not writing data when the crash occurred.
  442.  
  443.      Suppose we were using a RAID-1 array. In (2a), it might
  444.      happen that before the crash, a small number of data
  445.      blocks were successfully written only to some of the
  446.      mirrors, so that on the next reboot, the mirrors will no
  447.      longer contain the same data.
  448.  
  449.      If we ignore the mirror differences, the 0.36.3 read-
  450.      balancing code might choose to read the above data blocks
  451.      from any of the mirrors, which will result in
  452.      inconsistent behavior (for example, the output of e2fsck
  453.      -n /dev/md0 can differ from run to run).
  454.  
  455.      Since RAID doesn't protect against unclean shutdowns,
  456.      usually there isn't any ''obviously correct'' way to fix
  457.      the mirror differences and the filesystem corruption.
  458.  
  459.      For example, by default ckraid --fix will choose the
  460.      first operational mirror and update the other mirrors
  461.      with its contents.
  462.  
  463.      However, depending on the exact timing at the crash, the
  464.      data on another mirror might be more recent, and we might
  465.      want to use it as the source mirror instead, or perhaps
  466.      use another method for recovery.
  467.  
  468.      If you wish to run ckraid --fix automatically, you can
  469.      check the return code of mdrun for errors. For example:
  470.  
  471.          mdrun -p1 /dev/md0
  472.          if [ $? -gt 0 ] ; then
  473.                  ckraid --fix /etc/raid1.conf
  474.                  mdrun -p1 /dev/md0
  475.          fi
  476.  
  477.   3.  Error Recovery
  478.  
  479.   1. Q: I have a RAID-1 (mirroring) setup, and lost power while there
  480.      was disk activity.  Now what do I do?
  481.  
  482.        A: The redundancy of RAID levels is designed to protect
  483.        against a disk failure, not against a power failure.
  484.  
  485.        There are several ways to recover from this situation.
  486.  
  487.        ╖  Method (1): Use the raid tools.  These can be used to
  488.           sync the raid arrays.  They do not fix file-system
  489.           damage; after the raid arrays are sync'ed, then the file-
  490.           system still has to be fixed with fsck.  Raid arrays can
  491.           be checked with ckraid /etc/raid1.conf (for RAID-1, else,
  492.           /etc/raid5.conf, etc.)
  493.  
  494.           Calling ckraid /etc/raid1.conf --fix will pick one of the
  495.           disks in the array (usually the first), and use that as
  496.           the master copy, and copy its blocks to the others in the
  497.           mirror.
  498.  
  499.           To designate which of the disks should be used as the
  500.           master, you can use the --force-source flag: for example,
  501.           ckraid /etc/raid1.conf --fix --force-source /dev/hdc3
  502.  
  503.           The ckraid command can be safely run without the --fix
  504.           option to verify the inactive RAID array without making
  505.           any changes.  When you are comfortable with the proposed
  506.           changes, supply the --fix  option.
  507.  
  508.        ╖  Method (2): Paranoid, time-consuming, not much better
  509.           than the first way.  Lets assume a two-disk RAID-1 array,
  510.           consisting of partitions /dev/hda3 and /dev/hdc3.  You
  511.           can try the following:
  512.  
  513.           a. fsck /dev/hda3
  514.  
  515.           b. fsck /dev/hdc3
  516.  
  517.      c. decide which of the two partitions had fewer errors,
  518.         or were more easily recovered, or recovered the data
  519.         that you wanted.  Pick one, either one, to be your new
  520.         ``master'' copy.  Say you picked /dev/hdc3.
  521.  
  522.      d. dd if=/dev/hdc3 of=/dev/hda3
  523.  
  524.      e. mkraid raid1.conf -f --only-superblock
  525.  
  526.      Instead of the last two steps, you can instead run ckraid
  527.      /etc/raid1.conf --fix --force-source /dev/hdc3 which
  528.      should be a bit faster.
  529.  
  530.   ╖  Method (3): Lazy man's version of above.  If you don't
  531.      want to wait for long fsck's to complete, it is perfectly
  532.      fine to skip the first three steps above, and move
  533.      directly to the last two steps.  Just be sure to run fsck
  534.      /dev/md0 after you are done.  Method (3) is actually just
  535.      method (1) in disguise.
  536.  
  537.      In any case, the above steps will only sync up the raid
  538.      arrays.  The file system probably needs fixing as well:
  539.      for this, fsck needs to be run on the active, unmounted
  540.      md device.
  541.  
  542.      With a three-disk RAID-1 array, there are more
  543.      possibilities, such as using two disks to ''vote'' a
  544.      majority answer.  Tools to automate this do not currently
  545.      (September 97) exist.
  546.  
  547.   2. Q: I have a RAID-4 or a RAID-5 (parity) setup, and lost power while
  548.      there was disk activity.  Now what do I do?
  549.  
  550.        A: The redundancy of RAID levels is designed to protect
  551.        against a disk failure, not against a power failure.
  552.  
  553.        Since the disks in a RAID-4 or RAID-5 array do not contain a
  554.        file system that fsck can read, there are fewer repair
  555.        options.  You cannot use fsck to do preliminary checking
  556.        and/or repair; you must use ckraid first.
  557.  
  558.        The ckraid command can be safely run without the --fix
  559.        option to verify the inactive RAID array without making any
  560.        changes.  When you are comfortable with the proposed
  561.        changes, supply the --fix option.
  562.  
  563.        If you wish, you can try designating one of the disks as a
  564.        ''failed disk''.  Do this with the --suggest-failed-disk-
  565.        mask flag.  Only one bit should be set in the flag: RAID-5
  566.        cannot recover two failed disks.  The mask is a binary bit
  567.        mask: thus:
  568.  
  569.            0x1 == first disk
  570.            0x2 == second disk
  571.            0x4 == third disk
  572.            0x8 == fourth disk, etc.
  573.  
  574.        Alternately, you can choose to modify the parity sectors, by
  575.   using the --suggest-fix-parity flag.  This will recompute
  576.   the parity from the other sectors.
  577.  
  578.   The flags --suggest-failed-dsk-mask and --suggest-fix-parity
  579.   can be safely used for verification. No changes are made if
  580.   the --fix flag is not specified.  Thus, you can experiment
  581.   with different possible repair schemes.
  582.  
  583.   3. Q: My RAID-1 device, /dev/md0 consists of two hard drive
  584.      partitions: /dev/hda3 and /dev/hdc3.  Recently, the disk with
  585.      /dev/hdc3 failed, and was replaced with a new disk.  My best
  586.      friend, who doesn't understand RAID, said that the correct thing to
  587.      do now is to ''dd if=/dev/hda3 of=/dev/hdc3''.  I tried this, but
  588.      things still don't work.
  589.  
  590.        A: You should keep your best friend away from you computer.
  591.        Fortunately, no serious damage has been done.  You can
  592.        recover from this by running:
  593.  
  594.        mkraid raid1.conf -f --only-superblock
  595.  
  596.   By using dd, two identical copies of the partition were cre¡
  597.   ated. This is almost correct, except that the RAID-1 kernel
  598.   extension expects the RAID superblocks to be different.
  599.   Thus, when you try to reactivate RAID, the software will
  600.   notice the problem, and deactivate one of the two parti¡
  601.   tions.  By re-creating the superblock, you should have a
  602.   fully usable system.
  603.  
  604.   4. Q: My RAID-1 device, /dev/md0 consists of two hard drive
  605.      partitions: /dev/hda3 and /dev/hdc3.  My best (girl?)friend, who
  606.      doesn't understand RAID, ran fsck on /dev/hda3 while I wasn't
  607.      looking, and now the RAID won't work. What should I do?
  608.  
  609.        A: You should re-examine your concept of ``best friend''.
  610.        In general, fsck should never be run on the individual par¡
  611.        titions that compose a RAID array.  Assuming that neither of
  612.        the partitions are/were heavily damaged, no data loss has
  613.        occurred, and the RAID-1 device can be recovered as follows:
  614.  
  615.           a. make a backup of the file system on /dev/hda3
  616.  
  617.           b. dd if=/dev/hda3 of=/dev/hdc3
  618.  
  619.           c. mkraid raid1.conf -f --only-superblock
  620.  
  621.        This should leave you with a working disk mirror.
  622.  
  623.   5. Q: Why does the above work as a recovery procedure?
  624.  
  625.        A: Because each of the component partitions in a RAID-1 mir¡
  626.        ror is a perfectly valid copy of the file system.  In a
  627.        pinch, mirroring can be disabled, and one of the partitions
  628.   can be mounted and safely run as an ordinary, non-RAID file
  629.   system.  When you are ready to restart using RAID-1, then
  630.   unmount the partition, and follow the above instructions to
  631.   restore the mirror.   Note that the above works ONLY for
  632.   RAID-1, and not for any of the other levels.
  633.  
  634.   It may make you feel more comfortable to reverse the direc¡
  635.   tion of the copy above: copy from the disk that was
  636.   untouched to the one that was.  Just be sure to fsck the
  637.   final md.
  638.  
  639.   6. Q: I am confused by the above questions, but am not yet bailing
  640.      out.  Is it safe to run fsck /dev/md0 ?
  641.  
  642.        A: Yes, it is safe to run fsck on the md devices.  In fact,
  643.        this is the only safe place to run fsck.
  644.  
  645.   7. Q: If a disk is slowly failing, will it be obvious which one it is?
  646.      I am concerned that it won't be, and this confusion could lead to
  647.      some dangerous decisions by a sysadmin.
  648.  
  649.        A: Once a disk fails, an error code will be returned from
  650.        the low level driver to the RAID driver.  The RAID driver
  651.        will mark it as ``bad'' in the RAID superblocks of the
  652.        ``good'' disks (so we will later know which mirrors are good
  653.        and which aren't), and continue RAID operation on the
  654.        remaining operational mirrors.
  655.  
  656.        This, of course, assumes that the disk and the low level
  657.        driver can detect a read/write error, and will not silently
  658.        corrupt data, for example. This is true of current drives
  659.        (error detection schemes are being used internally), and is
  660.        the basis of RAID operation.
  661.  
  662.   8. Q: What about hot-repair?
  663.  
  664.        A: Work is underway to complete ``hot reconstruction''.
  665.        With this feature, one can add several ``spare'' disks to
  666.        the RAID set (be it level 1 or 4/5), and once a disk fails,
  667.        it will be reconstructed on one of the spare disks in run
  668.        time, without ever needing to shut down the array.
  669.  
  670.        However, to use this feature, the spare disk must have been
  671.        declared at boot time, or it must be hot-added, which
  672.        requires the use of special cabinets and connectors that
  673.        allow a disk to be added while the electrical power is on.
  674.  
  675.        As of October 97, there is a beta version of MD that allows:
  676.  
  677.        ╖  RAID 1 and 5 reconstruction on spare drives
  678.  
  679.        ╖  RAID-5 parity reconstruction after an unclean shutdown
  680.  
  681.        ╖  spare disk to be hot-added to an already running RAID 1
  682.           or 4/5 array
  683.  
  684.           By default, automatic reconstruction is (Dec 97)
  685.      currently disabled by default, due to the preliminary
  686.      nature of this work.  It can be enabled by changing the
  687.      value of SUPPORT_RECONSTRUCTION in include/linux/md.h.
  688.  
  689.      If spare drives were configured into the array when it
  690.      was created and kernel-based reconstruction is enabled,
  691.      the spare drive will already contain a RAID superblock
  692.      (written by mkraid), and the kernel will reconstruct its
  693.      contents automatically (without needing the usual mdstop,
  694.      replace drive, ckraid, mdrun steps).
  695.  
  696.      If you are not running automatic reconstruction, and have
  697.      not configured a hot-spare disk, the procedure described
  698.      by Gadi Oxman <gadio@netvision.net.il> is recommended:
  699.  
  700.   ╖  Currently, once the first disk is removed, the RAID set
  701.      will be running in degraded mode. To restore full
  702.      operation mode, you need to:
  703.  
  704.   ╖  stop the array (mdstop /dev/md0)
  705.  
  706.   ╖  replace the failed drive
  707.  
  708.   ╖  run ckraid raid.conf to reconstruct its contents
  709.  
  710.   ╖  run the array again (mdadd, mdrun).
  711.  
  712.      At this point, the array will be running with all the
  713.      drives, and again protects against a failure of a single
  714.      drive.
  715.  
  716.      Currently, it is not possible to assign single hot-spare
  717.      disk to several arrays.   Each array requires it's own
  718.      hot-spare.
  719.  
  720.   9. Q: I would like to have an audible alarm for ``you schmuck, one
  721.      disk in the mirror is down'', so that the novice sysadmin knows
  722.      that there is a problem.
  723.  
  724.        A: The kernel is logging the event with a ``KERN_ALERT''
  725.        priority in syslog.  There are several software packages
  726.        that will monitor the syslog files, and beep the PC speaker,
  727.        call a pager, send e-mail, etc. automatically.
  728.  
  729.   10.
  730.      Q: How do I run RAID-5 in degraded mode (with one disk failed, and
  731.      not yet replaced)?
  732.  
  733.        A: Gadi Oxman <gadio@netvision.net.il> writes:
  734.  
  735.        ╖  Normally, to run a RAID-5 set of n drives you have to:
  736.  
  737.        mdadd /dev/md0 /dev/disk1 ... /dev/disk(n)
  738.        mdrun -p5 /dev/md0
  739.  
  740.   Even if one of the disks has failed, you still have to mdadd
  741.   it as you would in a normal setup.  Then,
  742.  
  743.   ╖  The array will be active in degraded mode with (n - 1)
  744.      drives.  If ``mdrun'' fails, the kernel has noticed an
  745.      error (for example, several faulty drives, or an unclean
  746.      shutdown).  Use ``dmesg'' to display the kernel error
  747.      messages from ``mdrun''.
  748.  
  749.      If the raid-5 set is corrupted due to a power loss,
  750.      rather than a disk crash, one can try to recover by
  751.      creating a new RAID superblock:
  752.  
  753.        mkraid -f --only-superblock raid5.conf
  754.  
  755.   A RAID array doesn't provide protection against a power
  756.   failure or a kernel crash, and can't guarantee correct
  757.   recovery.  Rebuilding the superblock will simply cause the
  758.   system to ignore the condition by marking all the drives as
  759.   ``OK'', as if nothing happened.
  760.  
  761.   11.
  762.      Q: How does RAID-5 work when a disk fails?
  763.  
  764.        A: The typical operating scenario is as follows:
  765.  
  766.        ╖  A RAID-5 array is active.
  767.  
  768.        ╖  One drive fails while the array is active.
  769.  
  770.        ╖  The drive firmware and the low-level Linux
  771.           disk/controller drivers detect the failure and report an
  772.           error code to the MD driver.
  773.  
  774.        ╖  The MD driver continues to provide an error-free /dev/md0
  775.           device to the higher levels of the kernel (with a
  776.           performance degradation) by using the remaining
  777.           operational drives.
  778.  
  779.        ╖  The sysadmin can umount /dev/md0 and mdstop /dev/md0 as
  780.           usual.
  781.  
  782.        ╖  If the failed drive is not replaced, the sysadmin can
  783.           still start the array in degraded mode as usual, by
  784.           running mdadd and mdrun.
  785.  
  786.   12.
  787.      Q: The QuickStart says that mdstop is just to make sure that the
  788.      disks are sync'ed. Is this REALLY necessary? Isn't unmounting the
  789.      file systems enough?
  790.  
  791.        A: The command mdstop /dev/md0 will:
  792.  
  793.        ╖  mark it ''clean''. This allows us to detect unclean
  794.           shutdowns, for example due to a power failure or a kernel
  795.      crash.
  796.  
  797.   ╖  sync the array. This is less important after unmounting a
  798.      filesystem, but is important if the /dev/md0 is accessed
  799.      directly rather than through a filesystem (for example,
  800.      by e2fsck).
  801.  
  802.   13.
  803.      Q:
  804.  
  805.        A:
  806.  
  807.   14.
  808.      Q: Why is there no question 13?
  809.  
  810.        A: If you are concerned about RAID, High Availability, and
  811.        UPS, then its probably a good idea to be superstitious as
  812.        well.
  813.  
  814.   4.  Troubleshooting Install Problems
  815.  
  816.   1. Q: What is the current best known-stable patch for RAID in the
  817.      2.0.x series kernels?
  818.  
  819.        A: As of 18 Sept 1997, it is "2.0.30 + pre-9 2.0.31 + Werner
  820.        Fink's swapping patch + the alpha RAID patch".  As of Novem¡
  821.        ber 1997, it is 2.0.31 + ... !?
  822.  
  823.   2. Q: The RAID patches will not install cleanly for me.  What's wrong?
  824.  
  825.        A: Make sure that /usr/include/linux is a symbolic link to
  826.        /usr/src/linux/include/linux.
  827.  
  828.        Make sure that the new files raid5.c, etc.  have been copied
  829.        to their correct locations.  Sometimes the patch command
  830.        will not create new files.  Try the -f flag on patch.
  831.  
  832.   3. Q: While compiling raidtools 0.42, compilation stops trying to
  833.      include <pthread.h> but it doesn't exist in my system.  How do I
  834.      fix this?
  835.  
  836.        A: raidtools-0.42 requires linuxthreads-0.6 from:
  837.        <ftp://ftp.inria.fr/INRIA/Projects/cristal/Xavier.Leroy>
  838.        Alternately, use glibc v2.0.
  839.  
  840.   4. Q: I get the message: mdrun -a /dev/md0: Invalid argument
  841.  
  842.   A: Use mkraid to initialize the RAID set prior to the first
  843.   use.  mkraid ensures that the RAID array is initially in a
  844.   consistent state by erasing the RAID partitions. In addi¡
  845.   tion, mkraid will create the RAID superblocks.
  846.  
  847.   5. Q: I get the message: mdrun -a /dev/md0: Invalid argument The setup
  848.      was:
  849.  
  850.   ╖  raid1 build as a kernel module
  851.  
  852.   ╖  normal install procedure followed ... mdcreate, mdadd, etc.
  853.  
  854.   ╖  cat /proc/mdstat shows
  855.  
  856.          Personalities :
  857.          read_ahead not set
  858.          md0 : inactive sda1 sdb1 6313482 blocks
  859.          md1 : inactive
  860.          md2 : inactive
  861.          md3 : inactive
  862.  
  863.   ╖  mdrun -a creates the error message /dev/md0: Invalid argument
  864.  
  865.        A: Try lsmod to see if the modules is loaded, and if not,
  866.        load it with modprobe raid1.
  867.  
  868.   6. Q: Truxton Fulton wrote:
  869.  
  870.        On my Linux 2.0.30 system, while doing a mkraid for a RAID-1
  871.        device, during the clearing of the two individual parti¡
  872.        tions, I got "Cannot allocate free page" errors appearing on
  873.        the console, and "Unable to handle kernel paging request at
  874.        virtual address ..."  errors in the system log.  At this
  875.        time, the system became quite unusable, but it appears to
  876.        recover after a while.  The operation appears to have com¡
  877.        pleted with no other errors, and I am successfully using my
  878.        RAID-1 device.  The errors are disconcerting though.  Any
  879.        ideas?
  880.  
  881.        A: This was a well-known bug in the 2.0.30 kernels.  It is
  882.        fixed in the 2.0.31 kernel; alternately, fall back to
  883.        2.0.29.
  884.  
  885.   7. Q: I'm not able to mdrun a RAID-1, RAID-4 or RAID-5 device.  If I
  886.      try to mdrun a mdadd'ed device I get the message ''invalid raid
  887.      superblock magic''.
  888.  
  889.        A: Make sure that you've run the mkraid part of the install
  890.        procedure.
  891.  
  892.   8. Q: When I access /dev/md0, the kernel spits out a lot of errors
  893.      like md0: device not running, giving up !  and I/O error.... I've
  894.      successfully added my devices to the virtual device.
  895.  
  896.        A: To be usable, the device must be running. Use mdrun -px
  897.        /dev/md0 where x is l for linear, 0 for RAID-0 or 1 for
  898.        RAID-1, etc.
  899.  
  900.   9. Q: I've created a linear md-dev with 2 devices.  cat /proc/mdstat
  901.      shows the total size of the device, but df only shows the size of
  902.      the first physical device.
  903.  
  904.        A: You must mkfs your new md-dev before using it the first
  905.        time, so that the filesystem will cover the whole device.
  906.  
  907.   10.
  908.      Q: I've set up /etc/mdtab using mdcreate, I've mdadd'ed, mdrun and
  909.      fsck'ed my two /dev/mdX partitions.  Everything looks okay before a
  910.      reboot.  As soon as I reboot, I get an fsck error on both
  911.      partitions: fsck.ext2: Attempt to read block from filesystem
  912.      resulted in short read while trying too open /dev/md0.  Why?! How
  913.      do I fix it?!
  914.  
  915.        A: During the boot process, the RAID partitions must be
  916.        started before they can be fsck'ed.  This must be done in
  917.        one of the boot scripts.  For some distributions, fsck is
  918.        called from /etc/rc.d/rc.S, for others, it is called from
  919.        /etc/rc.d/rc.sysinit. Change this file to mdadd -ar *before*
  920.        fsck -A is executed.  Better yet, it is suggested that
  921.        ckraid be run if mdadd returns with an error.  How do do
  922.        this is discussed in greater detail in question 14 of the
  923.        section ''Error Recovery''.
  924.  
  925.   11.
  926.      Q: I get the message invalid raid superblock magic while trying to
  927.      run an array which consists of partitions which are bigger than
  928.      4GB.
  929.  
  930.        A: This bug is now fixed. (September 97)  Make sure you have
  931.        the latest raid code.
  932.  
  933.   12.
  934.      Q: I get the message Warning: could not write 8 blocks in inode
  935.      table starting at 2097175 while trying to run mke2fs on a partition
  936.      which is larger than 2GB.
  937.  
  938.        A: This seems to be a problem with mke2fs (November 97).  A
  939.        temporary work-around is to get the mke2fs code, and add
  940.        #undef HAVE_LLSEEK to e2fsprogs-1.10/lib/ext2fs/llseek.c
  941.        just before the first #ifdef HAVE_LLSEEK and recompile
  942.        mke2fs.
  943.  
  944.   13.
  945.      Q: ckraid currently isn't able to read /etc/mdtab
  946.  
  947.        A: The RAID0/linear configuration file format used in
  948.        /etc/mdtab is obsolete, although it will be supported for a
  949.        while more.  The current, up-to-date config files are cur¡
  950.        rently named /etc/raid1.conf, etc.
  951.  
  952.   14.
  953.      Q: The personality modules (raid1.o) are not loaded automatically;
  954.      they have to be manually modprobe'd before mdrun. How can this be
  955.      fixed?
  956.  
  957.        A: To autoload the modules, we can add the following to
  958.        /etc/conf.modules:
  959.  
  960.            alias md-personality-3 raid1
  961.            alias md-personality-4 raid5
  962.  
  963.   15.
  964.      Q: I've mdadd'ed 13 devices, and now I'm trying to mdrun -p5
  965.      /dev/md0 and get the message: /dev/md0: Invalid argument
  966.  
  967.        A: The default configuration for software RAID is 8 real
  968.        devices. Edit linux/md.h, change #define MAX_REAL=8 to a
  969.        larger number, and rebuild the kernel.
  970.  
  971.   16.
  972.      Q: I can't make md work with partitions on our latest SPARCstation
  973.      5.  I suspect that this has something to do with disk-labels.
  974.  
  975.        A: Sun disk-labels sit in the first 1K of a partition.  For
  976.        RAID-1, the Sun disk-label is not an issue since ext2fs will
  977.        skip the label on every mirror.  For other raid levels (0,
  978.        linear and 4/5), this appears to be a problem; it has not
  979.        yet (Dec 97) been addressed.
  980.  
  981.   5.  Supported Hardware
  982.  
  983.   1. Q: I have SCSI adapter brand XYZ (with or without several
  984.      channels), and disk brand(s) PQR and LMN, will these work with md
  985.      to create a linear/stripped/mirrored personality?
  986.  
  987.        A: Yes!  Software RAID will work with any disk controller
  988.        (IDE or SCSI) and any disks.  The disks do not have to be
  989.        identical, nor do the controllers.  For example, a RAID mir¡
  990.        ror can be created with one half the mirror being a SCSI
  991.        disk, and the other an IDE disk.  The disks do not even have
  992.        to be the same size.  There are no restrictions on the
  993.   mixing & matching of disks and controllers.
  994.  
  995.   This is because Software RAID works with disk partitions,
  996.   not with the raw disks themselves.  The only recommendation
  997.   is that for RAID levels 1 and 5, the disk partitions that
  998.   are used as part of the same set be the same size. If the
  999.   partitions used to make up the RAID 1 or 5 array are not the
  1000.   same size, then the excess space in the larger partitions is
  1001.   wasted (not used).
  1002.  
  1003.   2. Q: I have a twin channel BT-952, and the box states that it
  1004.      supports hardware RAID 0, 1 and 0+1.   I have made a RAID set with
  1005.      two drives, the card apparently recognizes them when it's doing
  1006.      it's BIOS startup routine. I've been reading in the driver source
  1007.      code, but found no reference to the hardware RAID support.  Anybody
  1008.      out there working on that?
  1009.  
  1010.        A: The Mylex/BusLogic FlashPoint boards with RAIDPlus are
  1011.        actually software RAID, not hardware RAID at all.  RAIDPlus
  1012.        is only supported on Windows 95 and Windows NT, not on Net¡
  1013.        ware or any of the Unix platforms.  Aside from booting and
  1014.        configuration, the RAID support is actually in the OS
  1015.        drivers.
  1016.  
  1017.        While in theory Linux support for RAIDPlus is possible, the
  1018.        implementation of RAID-0/1/4/5 in the Linux kernel is much
  1019.        more flexible and should have superior performance, so
  1020.        there's little reason to support RAIDPlus directly.
  1021.  
  1022.   6.  Modifying an Existing Installation
  1023.  
  1024.   1. Q: Are linear MD's expandable?  Can a new hard-drive/partition be
  1025.      added, and the size of the existing file system expanded?
  1026.  
  1027.        A: Miguel de Icaza <miguel@luthien.nuclecu.unam.mx> writes:
  1028.  
  1029.        I changed the ext2fs code to be aware of multiple-devices
  1030.        instead of the regular one device per file system assump¡
  1031.        tion.
  1032.  
  1033.        So, when you want to extend a file system, you run a utility
  1034.        program that makes the appropriate changes on the new device
  1035.        (your extra partition) and then you just tell the system to
  1036.        extend the fs using the specified device.
  1037.  
  1038.        You can extend a file system with new devices at system
  1039.        operation time, no need to bring the system down (and when¡
  1040.        ever I get some extra time, you will be able to remove
  1041.        devices from the ext2 volume set, again without even having
  1042.        to go to single-user mode or any hack like that).
  1043.  
  1044.        You can get the patch for 2.1.x kernel from my web page:
  1045.  
  1046.        <http://www.nuclecu.unam.mx/~miguel/ext2-volume>
  1047.  
  1048.   2. Q: Can I add disks to a RAID-5 array?
  1049.  
  1050.        A: Currently, (September 1997) no, not without erasing all
  1051.        data. A conversion utility to allow this does not yet exist.
  1052.        The problem is that the actual structure and layout of a
  1053.        RAID-5 array depends on the number of disks in the array.
  1054.  
  1055.        Of course, one can add drives by backing up the array to
  1056.        tape, deleting all data, creating a new array, and restoring
  1057.        from tape.
  1058.  
  1059.   3. Q: What would happen to my RAID1/RAID0 sets if I shift one of the
  1060.      drives from being /dev/hdb to /dev/hdc?
  1061.  
  1062.      Because of cabling/case size/stupidity issues, I had to make my
  1063.      RAID sets on the same IDE controller (/dev/hda and /dev/hdb). Now
  1064.      that I've fixed some stuff, I want to move /dev/hdb to /dev/hdc.
  1065.  
  1066.      What would happen if I just change the /etc/mdtab and
  1067.      /etc/raid1.conf files to reflect the new location?
  1068.  
  1069.        A: For RAID-0/linear, one must be careful to specify the
  1070.        drives in exactly the same order. Thus, in the above exam¡
  1071.        ple, if the original config is
  1072.  
  1073.        mdadd /dev/md0 /dev/hda /dev/hdb
  1074.  
  1075.   Then the new config *must* be
  1076.  
  1077.        mdadd /dev/md0 /dev/hda /dev/hdc
  1078.  
  1079.   For RAID-1/4/5, the drive's ''RAID number'' is stored in its
  1080.   RAID superblock, and therefore the order in which the disks
  1081.   are specified is not important.
  1082.  
  1083.   RAID-0/linear does not have a superblock due to it's older
  1084.   design, and the desire to maintain backwards compatibility
  1085.   with this older design.
  1086.  
  1087.   7.  Performance, Tools & General Bone-headed Questions
  1088.  
  1089.   1. Q: I've created a RAID-0 device on /dev/sda2 and /dev/sda3. The
  1090.      device is a lot slower than a single partition. Isn't md a pile of
  1091.      junk?
  1092.  
  1093.        A: To have a RAID-0 device running a full speed, you must
  1094.        have partitions from different disks.  Besides, putting the
  1095.        two halves of the mirror on the same disk fails to give you
  1096.        any protection whatsoever against disk failure.
  1097.   2. Q: I have 2 Brand X super-duper hard disks and a Brand Y
  1098.      controller.  and am considering using md.  Does it significantly
  1099.      increase the throughput?  Is the performance really noticeable?
  1100.  
  1101.        A: The answer depends on the configuration that you use.
  1102.  
  1103.           Linux MD RAID-0 (striping) performance:
  1104.              Must wait for all disks to read/write the stripe.
  1105.  
  1106.           Linux MD RAID-1 (mirroring) read performance:
  1107.              MD implements read balancing. In a low-IO situation,
  1108.              this won't change performance.  But, with two disks in
  1109.              a high-IO environment, this could as much as double
  1110.              the read performance.  For N disks in the mirror, this
  1111.              could improve performance N-fold.
  1112.  
  1113.           Linux MD RAID-1 (mirroring) write performance:
  1114.              Must wait for the write to occur to all of the disks
  1115.              in the mirror.
  1116.  
  1117.   3. Q: What is the optimal RAID-5 configuration for performance?
  1118.  
  1119.        A: Since RAID-5 attempts to equally distribute the I/O load
  1120.        across several drives, the best performance will be obtained
  1121.        when the RAID set is balanced by using identical drives,
  1122.        identical controllers,  and the same (low) number of drives
  1123.        on each controller.
  1124.  
  1125.        Note, however, that using identical components might raise
  1126.        the probability of multiple drives failures.
  1127.  
  1128.   4. Q: What is the optimal block size for a RAID-4/5 array?
  1129.  
  1130.        A: When using the current (November 1997) RAID-4/5 implemen¡
  1131.        tation, it is strongly recommended that the file system be
  1132.        created with mke2fs -b 4096 instead of the default 1024 byte
  1133.        filesystem block size.
  1134.  
  1135.        This is because the current RAID-5 implementation allocates
  1136.        one 4K memory page per disk block; thus 75% of the memory
  1137.        which RAID-5 is allocating for pending I/O is not being
  1138.        used.  With a 4096 block size, it will potentially queue 4
  1139.        times as much pending I/O to the low level drivers without
  1140.        allocating additional memory.
  1141.  
  1142.        Note: the 4K memory page size applies to the Intel x86
  1143.        architecture.  I think memory pages are 8K on Alpha/Sparc
  1144.        (????), and thus the above figures should be adjusted
  1145.        accordingly.
  1146.  
  1147.        Note: if your file system has a lot of small files (files
  1148.        less than 10KBytes in size), a considerable fraction of the
  1149.        disk space might be wasted.  This is because disk space is
  1150.        allocated in multiples of the block size.  Allocating large
  1151.        blocks for small files clearly results in a waste of disk
  1152.        space.
  1153.  
  1154.        Note: the above remarks do NOT apply to Software
  1155.   RAID-0/1/linear.
  1156.  
  1157.   Note: most ''typical'' systems do not have that many small
  1158.   files.  That is, although there might be thousands of small
  1159.   files, this would lead to only some 10 to 100MB wasted
  1160.   space, which is probably an acceptable tradeoff for perfor¡
  1161.   mance on a multi-gigabyte disk.
  1162.  
  1163.   Note: for news servers, there might be tens or hundreds of
  1164.   thousands of small files.  In such cases, the smaller block
  1165.   size may be more important than the improved performance.
  1166.  
  1167.   Note: there exists an experimental file system for Linux
  1168.   which packs small files and file chunks onto a single block.
  1169.   It apparently has some very positive performance implica¡
  1170.   tions when the average file size is much smaller than the
  1171.   block size.
  1172.  
  1173.   Note: Future versions may implement schemes that obsolete
  1174.   the above discussion. However, this is difficult to imple¡
  1175.   ment, since dynamic run-time allocation can lead to dead-
  1176.   locks; the current implementation performs a static pre-
  1177.   allocation.
  1178.  
  1179.   5. Q: How does the chunk size influence the speed of my RAID device?
  1180.  
  1181.        A: The chunk size is the amount of data contiguous on the
  1182.        virtual device that is also contiguous on the physical
  1183.        device. Depending on your workload, the best is to let the
  1184.        chunk size match the size of your requests, so two requests
  1185.        have chances to be on different disks, and to be run the
  1186.        same time. This suppose a lot of testing with different
  1187.        chunk sizes to match the average request size, and to have
  1188.        the best performances.
  1189.  
  1190.   6. Q: Where can I put the md commands in the startup scripts, so that
  1191.      everything will start automatically at boot time?
  1192.  
  1193.        A: Rod Wilkens <rwilkens@border.net> writes:
  1194.  
  1195.        What I did is put ``mdadd -ar'' in the
  1196.        ``/etc/rc.d/rc.sysinit'' right after the kernel loads the
  1197.        modules, and before the ``fsck'' disk check.  This way, you
  1198.        can put the ``/dev/md?'' device in the ``/etc/fstab''. Then
  1199.        I put the ``mdstop -a'' right after the ``umount -a''
  1200.        unmounting the disks, in the ``/etc/rc.d/init.d/halt'' file.
  1201.  
  1202.   For raid-5, you will want to look at the return code for mdadd, and if
  1203.   it failed, do a
  1204.  
  1205.        ckraid --fix /etc/raid5.conf
  1206.  
  1207.   to repair any damage.
  1208.  
  1209.   7. Q: I was wondering if it's possible to setup stripping with more
  1210.      than 2 devices in md0? This is for a news server, and I have 9
  1211.      drives... Needless to say I need much more than two.  Is this
  1212.      possible?
  1213.  
  1214.        A: Yes. (describe how to do this)
  1215.  
  1216.   8. Q: When is Software RAID superior to Hardware RAID?
  1217.  
  1218.        A: Normally, Hardware RAID is considered superior to Soft¡
  1219.        ware RAID, because hardware controllers often have a large
  1220.        cache, and can do a better job of scheduling operations in
  1221.        parallel.  However, integrated Software RAID can (and does)
  1222.        gain certain advantages from being close to the operating
  1223.        system.
  1224.  
  1225.        For example, ... ummm. Opaque description of caching of
  1226.        reconstructed blocks in buffer cache elided ...
  1227.  
  1228.        On a dual PPro SMP system, it has been reported that Soft¡
  1229.        ware-RAID performance exceeds the performance of a well-
  1230.        known hardware-RAID board vendor by a factor of 2 to 5.
  1231.  
  1232.        Software RAID is also a very interesting option for high-
  1233.        availability redundant server systems.  In such a configura¡
  1234.        tion, two CPU's are attached to one set or SCSI disks.  If
  1235.        one server crashes or fails to respond, then the other
  1236.        server can mdadd, mdrun and mount the software RAID array,
  1237.        and take over operations.  This sort of dual-ended operation
  1238.        is not always possible with many hardware RAID controllers,
  1239.        because of the state configuration that the hardware con¡
  1240.        trollers maintain.
  1241.  
  1242.   9. Q: If I upgrade my version of raidtools, will it have trouble
  1243.      manipulating older raid arrays?  In short, should I recreate my
  1244.      RAID arrays when upgrading the raid utilities?
  1245.  
  1246.        A: No, not unless the major version number changes.  An MD
  1247.        version x.y.z consists of three sub-versions:
  1248.  
  1249.             x:      Major version.
  1250.             y:      Minor version.
  1251.             z:      Patchlevel version.
  1252.  
  1253.        Version x1.y1.z1 of the RAID driver supports a RAID array
  1254.        with version x2.y2.z2 in case (x1 == x2) and (y1 >= y2).
  1255.  
  1256.        Different patchlevel (z) versions for the same (x.y) version
  1257.        are designed to be mostly compatible.
  1258.  
  1259.        The minor version number is increased whenever the RAID
  1260.        array layout is changed in a way which is incompatible with
  1261.        older versions of the driver. New versions of the driver
  1262.        will maintain compatibility with older RAID arrays.
  1263.  
  1264.        The major version number will be increased if it will no
  1265.        longer make sense to support old RAID arrays in the new
  1266.   kernel code.
  1267.  
  1268.   For RAID-1, it's not likely that the disk layout nor the
  1269.   superblock structure will change anytime soon.  Most all Any
  1270.   optimization and new features (reconstruction, multithreaded
  1271.   tools, hot-plug, etc.) doesn't affect the physical layout.
  1272.  
  1273.   10.
  1274.      Q: The command mdstop /dev/md0 says that the device is busy.
  1275.  
  1276.        A: There's a process that has a file open on /dev/md0, or
  1277.        /dev/md0 is still mounted.  Terminate the process or umount
  1278.        /dev/md0.
  1279.  
  1280.   11.
  1281.      Q: Are there performance tools?
  1282.  
  1283.        A: There is also a new utility called iotrace in the
  1284.        linux/iotrace directory. It reads /proc/io-trace and analy¡
  1285.        ses/plots it's output.  If you feel your system's block IO
  1286.        performance is too low, just look at the iotrace output.
  1287.  
  1288.   12.
  1289.      Q: I was reading the RAID source, and saw the value SPEED_LIMIT
  1290.      defined as 1024K/sec.  What does this mean?  Does this limit
  1291.      performance?
  1292.  
  1293.        A: SPEED_LIMIT is used to limit RAID reconstruction speed
  1294.        during automatic reconstruction.  Basically, automatic
  1295.        reconstruction allows you to e2fsck and mount immediately
  1296.        after an unclean shutdown, without first running ckraid.
  1297.        Automatic reconstruction is also used after a failed hard
  1298.        drive has been replaced.
  1299.  
  1300.        In order to avoid overwhelming the system while reconstruc¡
  1301.        tion is occurring, the reconstruction thread monitors the
  1302.        reconstruction speed and slows it down if its too fast.  The
  1303.        1M/sec limit was arbitrarily chosen as a reasonable rate
  1304.        which allows the reconstruction to finish reasonably
  1305.        rapidly, while creating only a light load on the system so
  1306.        that other processes are not interfered with.
  1307.  
  1308.   13.
  1309.      Q: What about ''spindle synchronization'' or ''disk
  1310.      synchronization''?
  1311.  
  1312.        A: Spindle synchronization is used to keep multiple hard
  1313.        drives spinning at exactly the same speed, so that their
  1314.        disk platters are always perfectly aligned.  This is used by
  1315.        some hardware controllers to better organize disk writes.
  1316.        However, for software RAID, this information is not used,
  1317.        and spindle synchronization might even hurt performance.
  1318.  
  1319.   8.  Questions Waiting for Answers
  1320.  
  1321.   1. Q: What are the option you have used for formating the (raid)
  1322.      disks?  I used:
  1323.  
  1324.        mke2fs -b 4096 -R stride=4 ... blah
  1325.  
  1326.   or is it supposed to be 64K ╫ 4 drives:
  1327.  
  1328.        mke2fs -b 4096 -R stride=262000 ... blah
  1329.  
  1330.   are there any other options ?
  1331.  
  1332.        stride blocks are filesystem blocks, not virtual memory
  1333.        pages.
  1334.  
  1335.        Is there a paper somewhere about what does the stride option
  1336.        do ?  Also, in relation with the ``md'' device driver ?
  1337.  
  1338.        The stride option serves only one purpose: it tells mke2fs
  1339.        how many file system blocks will be written to each member
  1340.        in turn.  This allows mke2fs to allocate the block and inode
  1341.        bitmaps so that they don't all end up on the same physical
  1342.        drive.  I noticed last spring that one drive in a pair
  1343.        always had a larger I/O count, and tracked it down to the
  1344.        these meta-data blocks.  Ted added the -R stride= option in
  1345.        response to my explanation and request for a workaround.
  1346.  
  1347.        > For a 4KB block file system, with stripe size 32KB, one
  1348.        would use -R > stride=8.
  1349.  
  1350.   2. Q: For testing the raw disk thru put...  is there a character
  1351.      device for raw read/raw writes instead of /dev/sdaxx that we can
  1352.      use to measure performance on the raid drives??  is there a GUI
  1353.      based tool to use to watch the disk thru-put??
  1354.  
  1355.   9.  Wish List of Enhancements to MD and Related Software
  1356.  
  1357.   Bradley Ward Allen <ulmo@Q.Net> wrote:
  1358.  
  1359.        Ideas include:
  1360.  
  1361.        ╖  Bootup parameters to tell the kernel which devices are to
  1362.           be MD devices (no more ``mdadd'')
  1363.  
  1364.        ╖  Making MD transparent to ``mount''/``umount'' such that
  1365.           there is no ``mdrun'' and ``mdstop''
  1366.  
  1367.   ╖  Integrating ``ckraid'' entirely into the kernel, and
  1368.      letting it run as needed
  1369.  
  1370.      (So far, all I've done is suggest getting rid of the
  1371.      tools and putting them into the kernel; that's how I feel
  1372.      about it, this is a filesystem, not a toy.)
  1373.  
  1374.   ╖  Deal with arrays that can easily survive N disks going
  1375.      out simultaneously or at separate moments, where N is a
  1376.      whole number > 0 settable by the administrator
  1377.  
  1378.   ╖  Handle kernel freezes, power outages, and other abrupt
  1379.      shutdowns better
  1380.  
  1381.   ╖  Don't disable a whole disk if only parts of it have
  1382.      failed, e.g., if the sector errors are confined to less
  1383.      than 50% of access over the attempts of 20 dissimilar
  1384.      requests, then it continues just ignoring those sectors
  1385.      of that particular disk.
  1386.  
  1387.   ╖  Bad sectors:
  1388.  
  1389.   ╖  A mechanism for saving which sectors are bad, someplace
  1390.      onto the disk.
  1391.  
  1392.   ╖  If there is a generalized mechanism for marking degraded
  1393.      bad blocks that upper filesystem levels can recognize,
  1394.      use that. Program it if not.
  1395.  
  1396.   ╖  Perhaps alternatively a mechanism for telling the upper
  1397.      layer that the size of the disk got smaller, even
  1398.      arranging for the upper layer to move out stuff from the
  1399.      areas being eliminated.  This would help with a degraded
  1400.      blocks as well.
  1401.  
  1402.   ╖  Failing the above ideas, keeping a small (admin settable)
  1403.      amount of space aside for bad blocks (distributed evenly
  1404.      across disk?), and using them (nearby if possible)
  1405.      instead of the bad blocks when it does happen.  Of
  1406.      course, this is inefficient.  Furthermore, the kernel
  1407.      ought to log every time the RAID array starts each bad
  1408.      sector and what is being done about it with a ``crit''
  1409.      level warning, just to get the administrator to realize
  1410.      that his disk has a piece of dust burrowing into it (or a
  1411.      head with platter sickness).
  1412.  
  1413.   ╖  Software-switchable disks:
  1414.  
  1415.      ``disable this disk''
  1416.         would block until kernel has completed making sure
  1417.         there is no data on the disk being shut down that is
  1418.         needed (e.g., to complete an XOR/ECC/other error
  1419.         correction), then release the disk from use (so it
  1420.         could be removed, etc.);
  1421.  
  1422.      ``enable this disk''
  1423.         would mkraid a new disk if appropriate and then start
  1424.         using it for ECC/whatever operations, enlarging the
  1425.         RAID5 array as it goes;
  1426.  
  1427.      ``resize array''
  1428.         would respecify the total number of disks and the
  1429.         number of redundant disks, and the result would often
  1430.         be to resize the size of the array; where no data loss
  1431.         would result, doing this as needed would be nice, but
  1432.         I have a hard time figuring out how it would do that;
  1433.         in any case, a mode where it would block (for possibly
  1434.         hours (kernel ought to log something every ten seconds
  1435.         if so)) would be necessary;
  1436.  
  1437.      ``enable this disk while saving data''
  1438.         which would save the data on a disk as-is and move it
  1439.         to the RAID5 system as needed, so that a horrific save
  1440.         and restore would not have to happen every time
  1441.         someone brings up a RAID5 system (instead, it may be
  1442.         simpler to only save one partition instead of two, it
  1443.         might fit onto the first as a gzip'd file even);
  1444.         finally,
  1445.  
  1446.      ``re-enable disk''
  1447.         would be an operator's hint to the OS to try out a
  1448.         previously failed disk (it would simply call disable
  1449.         then enable, I suppose).
  1450.  
  1451.